/****************************************************
	文件：UILoading.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/8/16 22:53:32
	功能：Loading 窗口
*****************************************************/

using UnityEngine;
using HTFramework.UIKit;
using HTDemo01;

namespace HTDemo01
{
    public class UILoading : WndBase
    {
        private LoadingPanel mLoadingPanel;
        public override void OnAwake(params object[] paramLst)
        {
            base.OnAwake(paramLst);
            mLoadingPanel = GetPanel<LoadingPanel>();
            mLoadingPanel.Txt_Title.text = "Loading";
        }

        public override void OnUpdate()
        {
            base.OnUpdate();
            mLoadingPanel.Sli_Progress.value = SceneMgr.Instance.LoadProgress / 100.0f;
            mLoadingPanel.Txt_Progress.text = string.Format("{0}%", SceneMgr.Instance.LoadProgress);
            if (SceneMgr.Instance.LoadProgress >= 100)
            {
                LoadSceneFirstUIPanel(SceneMgr.Instance.CurrentScene);
            }
        }

        /// <summary>
        /// 切换场景后加载指定Wnd
        /// </summary>
        /// <param name="sceneName"></param>
        private void LoadSceneFirstUIPanel(string sceneName)
        {
            if (sceneName == GConsts.LOGIN_SCENE) //切换到登录场景
            {
                UIMgr.Instance.OpenWnd(GConsts.LOGIN_PANEL); //加载登录UI
            }
            else if(sceneName == GConsts.LEVEL_SCENE)
            {
                UIMgr.Instance.OpenWnd(GConsts.LEVEL_PANEL); //加载关卡UI
            }
            UIMgr.Instance.CloseWnd(GConsts.LOADING_PANEL); //关闭自身，只隐藏、不销毁
        }

    }
}
